<?php
/*
 * @Date: 2025-08-09 01:28:52
 * @LastEditors: 贾二小 erxiao.jia@outlook.com
 * @LastEditTime: 2025-09-07 23:49:00
 * @FilePath: /admin-api/app/helper.php
 */

use App\Models\User;
use Illuminate\Support\Facades\Auth;

if (!function_exists('getTree')) {
    function getTree($data, $parent_id = 0)
    {
        $tree = [];
        foreach ($data as $k => $v) {
            if ($v['parent_id'] == $parent_id) {
                $v['children'] = getTree($data, $v['id']);
                if (empty($v['children'])) unset($v['children']);
                $tree[] = $v;
                unset($data[$k]);
            }
        }
        return $tree;
    }
}
